package com.Xingcang_Dianxue.WhutBank.Controllers.Client;

import com.Xingcang_Dianxue.WhutBank.Models.Transaction;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;

import java.net.URL;
import java.util.ResourceBundle;


public class TransactionCellController implements Initializable {
    private final Transaction transaction;
    @FXML
    private Label amount_lbl;
    @FXML
    private FontAwesomeIconView in_icon;
    @FXML
    private Button message_btn;
    @FXML
    private FontAwesomeIconView out_icon;
    @FXML
    private Label receiver_lbl;
    @FXML
    private Label sender_lbl;

    public TransactionCellController(Transaction transaction) {
        this.transaction = transaction;
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        sender_lbl.textProperty().bind(transaction.senderProperty());
        receiver_lbl.textProperty().bind(transaction.receiverProperty());
        amount_lbl.textProperty().bind(transaction.amountProperty().asString());
        transactionIcons();
    }


    private void transactionIcons() {
        if (transaction.typeProperty().get().equals("取款")) {
            in_icon.setFill(Color.RED);
            out_icon.setFill(Color.RED);
        } else if (transaction.typeProperty().get().equals("存款")) {
            in_icon.setFill(Color.GREEN);
            out_icon.setFill(Color.GREEN);
        } else {
            in_icon.setFill(Color.GREEN);
            out_icon.setFill(Color.rgb(240, 240, 240));
        }
    }

}
